#include "stdio.h"

int m,n,k,shu_n;
int data[30009],shu[30009];
			
void pai(int shu[30009],int a)
{
	int i,j;
		if (a<=shu[1])
		{
			++shu_n;
			memmove(shu+2,shu+1,sizeof(int)*(shu_n));
			shu[1]=a;
		}
		else if (a>=shu[shu_n])
		{
			++shu_n;
			shu[shu_n]=a;	
		}
		else 
		{
			++shu_n;
			j=1;
			while (a>shu[j]) ++j;
				
			memmove(shu+j+1,shu+j,sizeof(int)*(shu_n-j));	
			shu[j]=a;
		}
}

main()
{
	int i,j,in;
	int tq,q;
	int t;
	scanf("%d",&tq);	
	for (q=1;q<=tq;++q)
	{
	scanf("%d%d",&m,&n);
	k=1;
	shu_n=0;
	memset(data,0,sizeof(data));
	memset(shu,0,sizeof(shu));
	for (i=1;i<=m;++i) scanf("%d",&data[i]);
	shu_n=1;
	shu[1]=data[1];
	for (i=1;i<=n;++i)
	{
		scanf("%d",&in);
		if (in>shu_n)
		{
		for (j=shu_n+1;j<=in;++j)
			pai(shu,data[j]);
		}
		printf("%d\n",shu[k]);
		++k;
	}
	if (q!=tq) printf("\n");
	}	
	
}
 
